package com.zxkj.commonpatrol.repoisity;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.SPUtils;
import com.zxkj.commonpatrol.model.entity.SelectProjectEntrity;
import com.zxkj.commonpatrol.model.post.PostSearchProject;
import com.zxkj.commonpatrol.model.response.ProjectDetailResponse;
import com.zxkj.commonpatrol.model.response.RouteSystemResponse;
import com.zxkj.commonpatrol.model.response.SearchProjectResponse;
import com.zxkj.commonpatrol.net.ETFApiHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ProjectListRepoisity extends BaseRepository {
    public ProjectListRepoisity() {

    }
    //獲取系統類別
    public  void getRouteSystems(MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);


        ETFApiHelper.geRadomApi().getRouteSystems(map)
                .compose(Transformer.<RouteSystemResponse>switchSchedulers())
                .subscribe(new CommonObserver<RouteSystemResponse>() {
                    @Override
                    protected String setTag() {
                        return "RouteSystems";
                    }

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(RouteSystemResponse s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });

    }

    //初始化選擇項目列表
    public void  getSelectProject(int PageIndex,int PageSize ,int  type,String ProCode,String RouteTypeNo,String Filter,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);
        PostSearchProject  postSearchProject  =new PostSearchProject();
       postSearchProject.setProCode(ProCode);
       postSearchProject.setRouteTypeNo(RouteTypeNo);
       postSearchProject.setCategoryid(type);
        postSearchProject.setFilter(Filter);
        postSearchProject.setPageIndex(PageIndex);
        postSearchProject.setPageSize(PageSize);

        ETFApiHelper.geRadomApi().GetProjectDetail(map,new BaseHttpUtil<PostSearchProject>().convertVo2Json(postSearchProject))
                .compose(Transformer.<ProjectDetailResponse>switchSchedulers())
                .subscribe(new CommonObserver<ProjectDetailResponse>() {
                    @Override
                    protected String setTag() {
                        return "RouteSystems";
                    }

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(ProjectDetailResponse s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });

    }

}
